package com.casic.ops.handler.pipeline;

import com.casic.ops.configs.ApplicationContextUtil;
import com.casic.ops.runner.pipeline.node.DIYModelExecutableNode;
import com.casic.ops.runner.pipeline.node.EndExecutableNode;
import com.casic.ops.runner.pipeline.node.ExecutableNode;
import com.casic.ops.runner.pipeline.node.StartExecutableNode;
import com.casic.ops.runner.pipeline.node.build.*;
import com.casic.ops.runner.pipeline.node.command.ArtificialStickingPointExecutableNode;
import com.casic.ops.runner.pipeline.node.command.DIYImageExecuteCommandExecutableNode;
import com.casic.ops.runner.pipeline.node.command.ExecuteCommandExecutableNode;
import com.casic.ops.runner.pipeline.node.command.ReplaceEnvironmentCommandExecutableNode;
import com.casic.ops.runner.pipeline.node.deploy.*;
import com.casic.ops.runner.pipeline.node.scan.*;
import com.casic.ops.runner.pipeline.node.test.*;
import com.casic.ops.runner.pipeline.node.tool.HarborWarehouseBuildExecutableNode;
import com.casic.ops.runner.pipeline.node.tool.HelmChartDIYWarehouseBuildExecutableNode;
import com.casic.ops.runner.pipeline.node.tool.JenkinsTaskExecutableNode;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 节点执行类加载器，有多个if else，有点烂，这些执行类都加了@Scope(scopeName = "prototype")注解，用来解决重复自定义模板或重复人工卡点这些节点的并发问题,
 * @author cww
 * @date 2022/7/1
 * @desciption 这个类暂时用不上了，之前的老的节点执行类加载器加载的节点执行对象已经不会导致并发问题，因为把那些节点执行对象改造成无状态对象了，也就无需多例来解决并发问题了。
 */
@Service
public class PipelineExecutableNodeFactory {

    public ExecutableNode get(String name) {
        if(name.equals("START")){
            return ApplicationContextUtil.getBean(StartExecutableNode.class);
        }else if (name.equals("JAVA_BUILD")) {
            return ApplicationContextUtil.getBean(JavaBuildExecutableNode.class);
        } else if (name.equals("C/CPP_BUILD")) {
            return ApplicationContextUtil.getBean(C_CppBuildExecutableNode.class);
        } else if (name.equals("GO_BUILD")) {
            return ApplicationContextUtil.getBean(GoBuildExecutableNode.class);
        } else if (name.equals("IMAGE_BUILD")) {
            return ApplicationContextUtil.getBean(ImageBuildExecutableNode.class);
        } else if (name.equals("NODE_JS_BUILD")) {
            return ApplicationContextUtil.getBean(NodeJsBuildExecutableNode.class);
        } else if (name.equals("PYTHON_BUILD")) {
            return ApplicationContextUtil.getBean(PythonBuildExecutableNode.class);
        } else if (name.equals("PHP_BUILD")) {
            return ApplicationContextUtil.getBean(PhpBuildExecutableNode.class);
        } else if (name.equals("MANUAL_CLAMPING_POINT")) {
            return ApplicationContextUtil.getBean(ArtificialStickingPointExecutableNode.class);
        } else if (name.equals("CUSTOM_IMAGE_EXECUTION_COMMAND")) {
            return ApplicationContextUtil.getBean(DIYImageExecuteCommandExecutableNode.class);
        } else if (name.equals("EXECUTE_COMMAND")) {
            return ApplicationContextUtil.getBean(ExecuteCommandExecutableNode.class);
        } else if (name.equals("REPLACE_ENVIRONMENT_VARIABLES_IN_FILE")) {
            return ApplicationContextUtil.getBean(ReplaceEnvironmentCommandExecutableNode.class);
        } else if (name.equals("DOCKER_DEPLOY")) {
            return ApplicationContextUtil.getBean(DockerDeployExecuteNode.class);
        } else if (name.equals("ECS_APPLICATION_DEPLOYMENT")) {
            return ApplicationContextUtil.getBean(ECSAppDeployExecutableNode.class);
        } else if (name.equals("EDAS_KUBERNETES_APPLICATION")) {
            return ApplicationContextUtil.getBean(EDASK8sAppDeployExecutableNode.class);
        } else if (name.equals("HOST_DEPLOY")) {
            return ApplicationContextUtil.getBean(HostDeployExecutableNode.class);
        } else if (name.equals("KUBERNETES_RELEASED_IN_BATCHES")) {
            return ApplicationContextUtil.getBean(K8SBatchDeployExecutablNode.class);
        } else if (name.equals("KUBERNETES_BLUE_GREEN_RELEASE")) {
            return ApplicationContextUtil.getBean(K8SBlueGreenDeployExecutableNode.class);
        } else if (name.equals("KUBERNETES_RELEASE")) {
            return ApplicationContextUtil.getBean(K8SDeployExecutableNode.class);
        } else if (name.equals("KUBERNETES_IMAGE_UPGRADE")) {
            return ApplicationContextUtil.getBean(K8SImageUpdateExecutableNode.class);
        } else if (name.equals("PRIVATE_CLOUD_BUILD_DEPLOY")) {
            return ApplicationContextUtil.getBean(PrivateCloudBuildDeployExecutableNode.class);
        } else if (name.equals("CK_SCAN")) {
            return ApplicationContextUtil.getBean(CKScanExecutableNode.class);
        } else if (name.equals("GO_CODE_SCAN")) {
            return ApplicationContextUtil.getBean(GoCodeScanExecutableNode.class);
        } else if (name.equals("JACOBO_COLLECTION_COVERAGE")) {
            return ApplicationContextUtil.getBean(JacocoCoverageCollectExecutableNode.class);
        } else if (name.equals("JAVA_CODE_SCANNING")) {
            return ApplicationContextUtil.getBean(JavaCodeScanExecutableNode.class);
        } else if (name.equals("JAVASCRIPT_CODE_SCANNING")) {
            return ApplicationContextUtil.getBean(JavaScriptCodeScanExecutableNode.class);
        } else if (name.equals("JAVA_SECURITY_SCAN")) {
            return ApplicationContextUtil.getBean(JavaSecurityScanExecuteNode.class);
        } else if (name.equals("PYTHON_CODE_SCAN")) {
            return ApplicationContextUtil.getBean(PythonCodeScanExectuableNode.class);
        } else if (name.equals("PYTHON_RELIES_ON_SECURITY_SCANNING")) {
            return ApplicationContextUtil.getBean(PythonDependencySecurityScanExecutableNode.class);
        } else if (name.equals("PYTHON_CODE_SECURITY_SCAN")) {
            return ApplicationContextUtil.getBean(PythonSecurityScanExecutableNode.class);
        } else if (name.equals("SONARQUBE_CODE_CHECK_SCAN")) {
            return ApplicationContextUtil.getBean(SonaQubeCodeScanExecutableNode.class);
        } else if (name.equals("SOURCE_CODE_VULNERABILITY_DETECTION")) {
            return ApplicationContextUtil.getBean(SourceCodeVulnerabilityScanningExecutableNode.class);
        } else if (name.equals("TRACE_SOURCE_CODE_SCAN")) {
            return ApplicationContextUtil.getBean(TraceSourceCodeScanExecutableNode.class);
        } else if(name.equals("DIY_UNIT_TEST")) {
            return ApplicationContextUtil.getBean(DIYUnitTestExecutableNode.class);
        } else if(name.equals("GRADLE_UNIT_TEST")){
            return ApplicationContextUtil.getBean(GradleUnitTestExecutableNode.class);
        } else if(name.equals("MAVEN_UNIT_TEST")){
            return ApplicationContextUtil.getBean(MavenUnitTestExecutableNode.class);
        }else if(name.equals("NODE._JS_UNIT_TEST")){
            return ApplicationContextUtil.getBean(NodeJsUnitTestExecutableNode.class);
        }else if(name.equals("PYTHON_UNIT_TEST")){
            return ApplicationContextUtil.getBean(PythonUnitTestExecutableNode.class);
        }else if(name.equals("HARBOR_WAREHOUSE_BUILD")){
            return ApplicationContextUtil.getBean(HarborWarehouseBuildExecutableNode.class);
        }else if(name.equals("HELM_CHART_DIY_WAREHOUSE_BUILD")){
            return ApplicationContextUtil.getBean(HelmChartDIYWarehouseBuildExecutableNode.class);
        }else if(name.equals("JENKINS_MISSION")){
            return ApplicationContextUtil.getBean(JenkinsTaskExecutableNode.class);
        }else if(name.equals("DIY_MODEL")){
            return ApplicationContextUtil.getBean(DIYModelExecutableNode.class);
        } else {
            return ApplicationContextUtil.getBean(EndExecutableNode.class);
        }
    }
}
